﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace PerformanceTesting
{
    class Program
    {
        static void Main(string[] args)
        {
            Test(new ObjectLookTest());
            //Test(new SortedObjectLookTest());
            Test(new MTObjectLookTest());

            Console.ReadLine();
        }

        static void Test(IPerformanceTest test)
        {
            Stopwatch sw = new Stopwatch();

            Console.WriteLine("Running test: {0}", test.Name);
            Do("Initialize", sw, test.Initialize);

            Console.WriteLine("Running 100 executes...");
            sw.Start();

            for (Int32 i = 0; i < 100; i++)
            {
                test.Execute(i + 1);
            }

            sw.Stop();

            Console.WriteLine("Total test time: " + sw.Elapsed.ToString());
            Console.WriteLine("Time per iteration: {0}", (sw.ElapsedMilliseconds / 100) + " ms");

            Console.Write("Show log [y/n]: ");
            if (Console.ReadLine().ToLower() == "y")
            {
                String[] log = test.GetLog();
                foreach(String l in log)
                    Console.WriteLine(l);
            }
        }

        static void Do(String name, Stopwatch sw, Action axn)
        {
            Console.Write(name + ": ");
            sw.Start();
            axn();

            sw.Stop();
            Console.WriteLine(sw.Elapsed.ToString());
            sw.Reset();
        }
    }
}
